var c = 0;
var init ;
var g_data;
var tid;
var last_time;
var interval_time = 10000;

var t_template;

function t_additem(item, init) {

	html = t_template.replace(/{memberName}/g,item.memberName)
	.replace(/{auctionPrice}/g,item.auctionPrice)
	.replace(/{date}/g,item.date)
	;
	
	
	if (init == 0) {
		$(html).hide().insertAfter('#act_list dt')
				.slideDown("slow");
		$('#act_list dd:last').slideDown("slow");
		$('#act_list dd:last').remove();
	} else {
		$(html).insertAfter('#act_list dt').slideDown("slow");
		$('#act_list dd:last').slideDown("slow");
	}

}

function interval_update() {
	if (c >= g_data.length) {
		$.getJSON(source_url, function(data) {
			g_data = data;
			$.each(data, function(i, item) {
				c = i;
				if ($('#' + item.memberId).length == 0) {
					if (item.dateLine > last_time) {
						if(c >= init){
							t_additem(item, 0);
						}else{
							t_additem(item, 1);
						}
						
						last_time = item.dateLine;
					}					
				}
			});
			tid = setTimeout('interval_update()', interval_time);
		})
		return false;
	}

	var item = g_data[c];
	if (item.dateLine > last_time) {
		t_additem(item, 0);
		last_time = item.dateLine;

	}
	c++;
	tid = setTimeout('interval_update()', interval_time);

}

function t_update(template,init_count) {
	
	t_template = template;
	init = init_count;
	
	$.getJSON(source_url, function(data) {
		g_data = data;
		$.each(data, function(i, item) {
			c = i;
			
			if ($('#' + item.memberId).length == 0) {
				t_additem(item, 1)
				last_time = item.dateLine;
				if (c >= init_count) {
					c++;
					tid = setTimeout('interval_update()', interval_time);
					return false;
				}
			}
		});
		tid = setTimeout('interval_update()', interval_time);
	});
}